package mviewer.renderer.jogl;

import java.awt.Component;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import mviewer.renderer.IRenderer;
import mviewer.types.Camera;
import mviewer.types.IModel3d;

public class JoglRenderer implements IRenderer {

	private GLCanvas component;
	private SceneController glListener;

	@Override
	public void setModel(IModel3d model) {
		glListener.setModel(model);
	}

	@Override
	public void setCamera(Camera camera) {
		glListener.setCamera(camera);
	}

	@Override
	public Component createComponent() {
		if (component!=null)
			throw new IllegalStateException("Component already created. This instance can only handle one component instance.");

		GLCapabilities glc = new GLCapabilities(GLProfile.getDefault());

		glc.setNumSamples(2); // enable anti aliasing - just as a example
		glc.setSampleBuffers(true);
		glc.setHardwareAccelerated(true);

		component = new GLCanvas(glc);
		glListener = new SceneController();

		component.addGLEventListener(glListener);

		return component;
	}

	@Override
	public void display() {
		component.display();
	}
}
